package com.yuchting.dinneronline.client.common;

import com.google.gwt.json.client.JSONObject;


public class Order {
	
	private Long m_time = System.currentTimeMillis();

	private String m_username = "";

	private String	m_dinnerName = "";
		
	private double m_pay = 9.5f;
	
	private boolean m_commented = false;
	
	// sets and gets function
	//
	public long getTime(){return m_time;}
	
	public void setUserName(String _name){m_username = _name;}
	public String getUserName(){return m_username;}
	
	public void setDinnerName(String _dinner){m_dinnerName = _dinner;}
	public String getDinnerName(){return m_dinnerName;}
	
	
	public double getPayMoney(){return m_pay;}
	public void setPayMoney(double _money){m_pay = _money;}
	
	public boolean isCommented(){return m_commented;}
	
	public JSONObject toJSON(){
		
		YuchJSONObject t_result = new YuchJSONObject();
		try{
			t_result.put("time",m_time);
			t_result.put("user",m_username);
			t_result.put("dinner",m_dinnerName);
			t_result.put("pay",m_pay);
			t_result.put("commented",m_commented);
		}catch(Exception e){
			System.err.println("Order toJSON Error:");
			e.printStackTrace(System.err);
		}
		
		return t_result.m_json;
	}
	
	public void fromJSON(YuchJSONObject _json){
		try{
			
			m_time 			= _json.getLong("time");
			m_username 		= _json.getString("user");
			m_dinnerName 	= _json.getString("dinner");
			m_pay 			= _json.getDouble("pay");
			m_commented		= _json.getBoolean("commented");
			
		}catch(Exception e){
			System.err.println("Order fromJSON Error:");
			e.printStackTrace(System.err);
		}
	}
	
}
